<?php

$__FILEPATH__ = dirname(__FILE__)."/";
require_once($__FILEPATH__."./func_common.php");
require_once($__FILEPATH__."./class_def.php");
require_once($__FILEPATH__."./conf/info.php");
header("Content-Type: text/html; charset=UTF-8");

$PageArray = array();
$mysqli = GetMysqliInstance();

$strsql = "select id,title,user,keyword,in_time from bloglist where ";
if (isset($_GET["search"]))
{
	$search = $_GET["search"];
	$titlestr = "%".$search."%";
	$keystr = "%".$search."|%";
	$datestr = $search."%";
	$strsql .= "user=? or title like ? or keyword like ? or in_time like ?";
	$stmt = $mysqli->prepare($strsql);
	$stmt->bind_param("ssss", $search, $titlestr, $keystr, $datestr);
}
else if (isset($_GET["cid"]))
{
	$cid = intval($_GET["cid"]);
	$strsql .= "id in (select bid from BCLinkList where cid = $cid)";
	$stmt = $mysqli->prepare($strsql);
}
else if (isset($_GET["date"]))
{
	$search = $_GET["date"];
	$date = $_GET["date"]."%";
	$strsql .= "in_time like ?";
	$stmt = $mysqli->prepare($strsql);
	$stmt->bind_param("s", $date);
}
else if (isset($_GET["keyword"]))
{
	$search = $_GET["keyword"];
	$keyword = "%".$_GET["keyword"]."|%";
	$strsql .= "keyword like ?";
	$stmt = $mysqli->prepare($strsql);
	$stmt->bind_param("s", $keyword);
}

if (!isset($stmt))
{
	die("非法操作~");
}

$PageArray["bloglist"] = array();

$stmt->execute();
$stmt->bind_result($r_id,$r_title,$r_user,$r_keyword,$r_in_time);
while($stmt->fetch())
{
	$BlogItem = new BlogListItem();
	$BlogItem->id = intval($r_id);
	$BlogItem->title = $r_title;
	$BlogItem->user = $r_user;
	$BlogItem->in_time = $r_in_time;
	$BlogItem->keyword = substr($r_keyword, 0, strlen($r_keyword) - 1);
	$PageArray["bloglist"][] = $BlogItem;
}
$stmt->close();

$mysqli->close();
?>